<?php

namespace App\Http\Resources;

use App\Models\School;
use Illuminate\Http\Resources\Json\Resource;

class StudentResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => (string)$this->name,
            'sex' => (string)$this->sex,
            'id_code' => (string)$this->id_code,
            'school_name' => (string)$this->getSchoolName($this->school_id),
            'is_enroll' => (string)$this->is_enroll ? $this->is_enroll : ''
        ];
    }

    public function getSchoolName($school_id){
       $school = School::query()->where('school_code',$school_id)->first();
       $schoolName = $school->school_name;
       return $schoolName;
    }




}
